<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java中的Fork/Join框架 - 深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* 英雄区域样式 */
        .hero-section {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="%23ffffff" fill-opacity="0.1" d="M0,96L48,112C96,128,192,160,288,160C384,160,480,128,576,122.7C672,117,768,139,864,154.7C960,171,1056,181,1152,165.3C1248,149,1344,107,1392,85.3L1440,64L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>') no-repeat bottom;
            background-size: cover;
        }
        
        /* 卡片悬停效果 */
        .card {
            transition: all 0.3s ease;
            border: 1px solid rgba(0,0,0,0.05);
        }
        
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        /* 代码块样式 */
        pre {
            background: #2d3748;
            color: #e2e8f0;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            position: relative;
            font-size: 14px;
            line-height: 1.6;
        }
        
        pre::before {
            content: 'Java';
            position: absolute;
            top: 0;
            right: 0;
            background: #4a5568;
            color: #a0aec0;
            padding: 0.25rem 0.75rem;
            border-radius: 0 8px 0 8px;
            font-size: 12px;
            font-weight: 500;
        }
        
        /* 首字下沉 */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 引用样式 */
        .quote-box {
            border-left: 4px solid #667eea;
            background: linear-gradient(to right, rgba(102, 126, 234, 0.05), transparent);
            padding: 1.5rem 2rem;
            margin: 2rem 0;
            position: relative;
        }
        
        .quote-box::before {
            content: '\f10d';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            top: -10px;
            left: 20px;
            font-size: 2rem;
            color: #667eea;
            opacity: 0.3;
        }
        
        /* 数据可视化容器 */
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            margin: 2rem 0;
        }
        
        /* 章节标题样式 */
        .section-title {
            position: relative;
            padding-bottom: 1rem;
            margin-bottom: 2rem;
        }
        
        .section-title::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 60px;
            height: 3px;
            background: linear-gradient(to right, #667eea, #764ba2);
            border-radius: 2px;
        }
        
        /* 特性卡片 */
        .feature-card {
            background: white;
            border-radius: 12px;
            padding: 2rem;
            position: relative;
            overflow: hidden;
            transition: all 0.3s ease;
        }
        
        .feature-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 4px;
            background: linear-gradient(to right, #667eea, #764ba2);
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 30px rgba(0,0,0,0.15);
        }
        
        /* 代码高亮 */
        .highlight {
            background: linear-gradient(to right, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
            padding: 0.2rem 0.5rem;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 0.9em;
        }
        
        /* 滚动动画 */
        .fade-in {
            opacity: 0;
            transform: translateY(20px);
            transition: all 0.6s ease;
        }
        
        .fade-in.visible {
            opacity: 1;
            transform: translateY(0);
        }
    </style>
</head>
<body>
    <!-- 英雄区域 -->
    <section class="hero-section text-white py-20 relative">
        <div class="container mx-auto px-6 relative z-10">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                    <i class="fas fa-code-branch mr-4"></i>
                    Java中的Fork/Join框架
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    掌握并行计算的艺术，释放多核处理器的强大潜能
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-microchip mr-2"></i>多核优化
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-tasks mr-2"></i>分而治之
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-rocket mr-2"></i>高性能计算
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- 主要内容区域 -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- 引言卡片 -->
        <div class="card bg-white rounded-xl shadow-lg p-8 mb-12 fade-in">
            <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                随着多核处理器的普及，传统的单线程编程方式已经无法充分利用现代计算机的硬件优势。在这种背景下，<strong class="text-purple-600">Fork/Join框架</strong>作为Java 7引入的一项重要并发工具，为我们提供了一种高效的方式来处理那些可以被递归分割并行执行的任务。它利用了"<strong class="text-purple-600">分而治之</strong>"的思想，将大任务拆解成多个小任务，通过多线程并行执行来加速计算过程，最终合并结果，得到整体任务的结果。
            </p>
        </div>

        <!-- 核心概念可视化 -->
        <div class="mb-12 fade-in">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-6">
                <i class="fas fa-sitemap mr-3 text-purple-600"></i>
                Fork/Join工作原理
            </h2>
            <div class="mermaid">
                graph TD
                    A[大任务] -->|Fork| B[子任务1]
                    A -->|Fork| C[子任务2]
                    B -->|Fork| D[子任务1.1]
                    B -->|Fork| E[子任务1.2]
                    C -->|Fork| F[子任务2.1]
                    C -->|Fork| G[子任务2.2]
                    D -->|Join| H[结果1.1]
                    E -->|Join| I[结果1.2]
                    F -->|Join| J[结果2.1]
                    G -->|Join| K[结果2.2]
                    H --> L[合并结果1]
                    I --> L
                    J --> M[合并结果2]
                    K --> M
                    L --> N[最终结果]
                    M --> N
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style N fill:#764ba2,stroke:#fff,stroke-width:3px,color:#fff
            </div>
        </div>

        <!-- 框架概述 -->
        <section class="mb-12 fade-in">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-6">
                <i class="fas fa-layer-group mr-3 text-purple-600"></i>
                Fork/Join框架概述
            </h2>
            
            <div class="quote-box">
                <p class="text-lg text-gray-700">
                    Fork/Join框架是Java 7引入的一个并发框架，专门用于<strong>解决那些可以分解为多个子任务并行执行的计算密集型问题</strong>。它的核心思想是通过<strong>分而治之</strong>（Divide and Conquer）的方法，将一个大任务拆分为多个小任务，在多个线程中并行执行，然后再将它们的结果合并。
                </p>
            </div>

            <div class="grid md:grid-cols-3 gap-6 mt-8">
                <div class="feature-card">
                    <div class="text-4xl text-purple-600 mb-4">
                        <i class="fas fa-tachometer-alt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">并行计算加速</h3>
                    <p class="text-gray-600">
                        将大任务拆分成小任务并行处理，极大提升多核处理器上并行执行的效率
                    </p>
                </div>
                
                <div class="feature-card">
                    <div class="text-4xl text-purple-600 mb-4">
                        <i class="fas fa-balance-scale"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">工作窃取算法</h3>
                    <p class="text-gray-600">
                        采用工作窃取算法高效分配任务，通过自适应负载均衡避免线程闲置
                    </p>
                </div>
                
                <div class="feature-card">
                    <div class="text-4xl text-purple-600 mb-4">
                        <i class="fas fa-code"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">简化并发编程</h3>
                    <p class="text-gray-600">
                        通过自动分配和合并任务，简化了并发编程的复杂性
                    </p>
                </div>
            </div>
        </section>

        <!-- 核心组件 -->
        <section class="mb-12 fade-in">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-6">
                <i class="fas fa-puzzle-piece mr-3 text-purple-600"></i>
                核心组件详解
            </h2>

            <!-- 组件关系图 -->
            <div class="mermaid mb-8">
                classDiagram
                    class ForkJoinPool {
                        +submit(ForkJoinTask)
                        +invoke(ForkJoinTask)
                        +execute(ForkJoinTask)
                        -workQueues[]
                        -workStealing()
                    }
                    
                    class ForkJoinTask {
                        <<abstract>>
                        +fork()
                        +join()
                        +invoke()
                        #compute()
                    }
                    
                    class RecursiveTask {
                        #compute() T
                    }
                    
                    class RecursiveAction {
                        #compute() void
                    }
                    
                    ForkJoinTask <|-- RecursiveTask
                    ForkJoinTask <|-- RecursiveAction
                    ForkJoinPool --> ForkJoinTask : manages
            